<template>
	<Modal v-model="modal"  title="选择图片" width="1040" :mask-closable="false" >
        <Alert>微信图片上传服务有敏感检测系统，图片内容如果含有敏感内容，如色情，商品推广，虚假信息等，回复可能失败</Alert>
		<ImageView :callback="chosieCallBack" ref="imageview"></ImageView>
		<div slot="footer">
            <Button type="primary" :disabled="disabled" @click="ok">确定</Button>
            <Button @click="cancel">取消</Button>
        </div>
	</Modal>
</template>
<script>
    import {Alert,Button,Modal} from 'iview';

	import ImageView from 'admin/components/wechat/manager/material/mpnews/image/image-view';
	export default{
		props :{
            callback:{
                type: Function,
                required : true,
            },
        },
		components:{
			Modal,
            ImageView,
            Button,
            Alert,
        },
        data () {
            return {
                modal :false,
                disabled: true,
                choise_id : 0,
            }
        },
        methods:{
        	//确定
            ok(){
            	this.modal = false;
            	this.callback(this.choise_id);
            },
            //取消
            cancel(){
            	this.modal = false;
            },
        	getData(){
        		this.$refs.imageview.init();
        	},
        	chosieCallBack(url,id){
        		if(this.choise_id==id || id==0){
            		this.choise_id= 0;
            		this.disabled = true;
            	}else{
            		this.disabled = false;
            		this.choise_id = id;	
            	}
        	},
        },
        watch:{
        	modal(newVue,oldVue){
        		this.disabled = true;
        		this.choise_id = 0;
        		if(newVue){
        			this.getData();
        		}
        	}
        }
	}
</script>